<template>
  <div ref="mainCon" class="container">
    <topTitle
      v-if="!hiddleToolBar"
      :titleText="titleText"
      :titleExplain="titleExplain"
    ></topTitle>
    <div class="mainCon">
      <el-row class="searchBox searchInputWidth">
        <el-form :inline="true" :model="filterField" ref="accountForm">
          <el-col :lg="8" :xl="6">
            <el-form-item label="申请日期" class="row-padding-bottom">
              <timeSelection
                @getStartTimeValue="getStartTimeValue"
                @getEndTimeValue="getEndTimeValue"
              ></timeSelection>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="申请单位" class="row-padding-bottom">
              <el-input
                placeholder="名称或统一社会信用代码"
                clearable
                v-model="filterField.keyword"
                @blur="filterField.keyword = changeValue($event)"
              ></el-input>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="归属" class="row-padding-bottom">
                <el-select
                  v-model="filterField.belongs"
                  placeholder="请选择"
                  clearable
                  :popper-append-to-body="false"
                >
                  <el-option label="本地企业" value="1"></el-option>
                  <el-option label="外地企业" value="2"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="经营区域" class="row-padding-bottom">
                <el-cascader
                  ref="manageArea"
                  v-model="bizAreaId"
                  :options="areasOptions"
                  @change="getAreaId"
                  clearable
                  filterable
                  :append-to-body="false"
                  :props="{ checkStrictly: true }"
                  placeholder="请选择"
                ></el-cascader>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="行业" prop="industry">
                <el-cascader
                  ref="industry"
                  v-model="industryId"
                  :options="industryOptionsNC"
                  @change="getIndustryId"
                  :props="{ checkStrictly: true }"
                  :append-to-body="false"
                  clearable
                ></el-cascader>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="单位类型" class="row-padding-bottom">
                <el-select
                  v-model="filterField.departmentType"
                  placeholder="请选择"
                  clearable
                  :popper-append-to-body="false"
                >
                  <el-option label="企业" value="0"></el-option>
                  <el-option label="事业单位" value="5"></el-option>
                  <el-option label="个体工商户" value="15"></el-option>
                  <el-option label="其他" value="10"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <!-- <el-form-item>
                        <el-button type="primary" icon="icon iconfont iconchazhao1" @click="searchTable" class="commonBtn"></el-button>
                    </el-form-item> -->
          </template>
          <el-col :lg="8" :xl="6">
            <el-form-item label="">
              <a
                @click="toggleAdvanced"
                style="margin-left: 40px; color: #409eff; cursor: pointer"
                class="btnColor"
              >
                {{ advanced ? '收起' : '展开' }}
                <i
                  :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                ></i>
              </a>
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchTable"
                class="searchBtn"
              >
                <span>搜索</span>
              </el-button>
            </el-form-item>
            <el-form-item>
              <exportBtn
                :dataLen="tableData.length"
                :filterField="filterField"
                :api="api"
              ></exportBtn>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <!-- 列表 -->
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <el-table
          ref="tableBox1"
          :max-height="tableHeight"
          :data="tableData"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          @sort-change="sortChange"
          v-loading="loading"
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column
            prop="createTime"
            label="申请时间"
            sortable="custom"
            :formatter="formatTd"
            min-width="160"
          ></el-table-column>
          <el-table-column label="单位名称" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.name"
                :columnName="'name'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="uscc"
            label="统一社会信用代码"
            :formatter="formatTd"
            min-width="200"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="departmentName"
            label="单位类型"
            :formatter="formatTd"
            min-width="160"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="belongs"
            label="归属"
            :formatter="formatTd"
            min-width="100"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="bizAreaName"
            label="区域"
            :formatter="formatTd"
            min-width="140"
          >
            <template slot-scope="scope">
              {{ scope.row.bizCityName }}-{{ scope.row.bizCountyName }}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="industryName"
            label="行业"
            :formatter="formatTd"
            min-width="180"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="status"
            label="审核状态"
            :formatter="formatTd"
            min-width="140"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="updaterName"
            label="审核人"
            :formatter="formatTd"
            min-width="140"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="updateTime"
            sortable="custom"
            label="审核时间"
            :formatter="formatTd"
            min-width="160"
          ></el-table-column>
          <el-table-column align="left" label="操作" width="110" fixed="right">
            <template slot-scope="scope">
              <div v-if="scope.row.status === '待审核' && hasPage">
                <el-link type="primary" @click="skipCheckPage(scope.row.id)"
                  >审核</el-link
                >
              </div>
              <!-- <div v-else-if="scope.row.status ==='待审核' && !hasPage">
                                <span>--</span>
                            </div> -->
              <div v-else>
                <el-link
                  type="primary"
                  @click="toDetail(scope.row)"
                  v-show="isShowDetail"
                  >查看详情</el-link
                >
              </div>
              <span v-show="!isShowDetail">--</span>
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <!-- filterField为搜索条件 -->
        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
          @getpageNo="getpageNo"
          @getpageSize="getpageSize"
        ></Pagination>
      </div>
    </div>
  </div>
</template>

<script>
import scrollTable from '@/mixin/scrollTable.js'
import { mapActions, mapState } from 'vuex'

export default {
  name: 'employerAuditList',
  mixins: [scrollTable],
  data() {
    return {
      titleText: '用人单位审核',
      advanced: false,
      titleExplain:
        '用人单位自行注册，需地区监察审核，审核通过后用人单位即可收到系统账号信息',
      requestUrl: 'api-c/companyaudit/expand/companyauditlist', //表格请求路径
      date: [], //申请日期
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now()
        },
      },
      loading: true,
      isShow: false,
      tableData: [], //表格数据
      industryId: '', //行业
      bizAreaId: '', //地址
      filterField: {
        beginDate: '',
        endDate: '',
        belongs: '', //归属
        bizAreaId: '', //地址
        industryId: '', //
        departmentType: '', //单位类型
        keyword: '', //申请企业名称/代码
      },
      pageSize: 20,
      pageNo: 1,
      hasPage: false,
      isShowDetail: '',
      api: '',
    }
  },
  computed: { ...mapState(['areasOptions', 'industryOptionsNC']) },
  created() {
    this.$store.state.activeMenu = '/home/enterpriseSet/employerAuditList'
    //获取行业
    this.getIndustryNC({})
    //获取区域
    this.getAreas({ areaId: this.$store.state.areaInfoArr.areaId })
    this.filterField.status = this.$route.query.pending
      ? this.$route.query.pending
      : ''
    this.filterField.keyword = this.$route.query.name
      ? this.$route.query.name
      : ''
    this.bizAreaId = this.$route.query.areaId ? this.$route.query.areaId : ''
    this.filterField.bizAreaId = this.bizAreaId
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
    this.getApi()
    this.hasPage =
      this.$store.state.buttonLimitsArr.indexOf('employerAuditList:update') > -1
    this.isShowDetail =
      this.$store.state.buttonLimitsArr.indexOf('employerAuditList:detail') > -1
  },
  activated() {
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData(this.pageNo, this.pageSize)
    })
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    getpageSize(val) {
      this.pageSize = val
    },
    getpageNo(val) {
      this.pageNo = val
    },
    ...mapActions(['getAreas', 'getIndustryNC']),
    /**
     * @description: 获取开始日期
     * @param {*} urls
     * @param {*} datas
     */
    getStartTimeValue(val) {
      if (val) {
        this.filterField.beginDate = val
      } else {
        this.filterField.beginDate = ''
      }
    },
    /**
     * @description: 获取结束日期
     * @param {*} urls
     * @param {*} datas
     */
    getEndTimeValue(val) {
      if (val) {
        this.filterField.endDate = val
      } else {
        this.filterField.endDate = ''
      }
    },
    getTableList(data) {
      this.tableData = data
      this.loading = false
      if (this.tableData.length < 1) {
        this.isShow = true
      }
    },
    //列表查询
    searchTable() {
      this.pageSize = 20
      this.pageNo = 1
      this.$refs.pagination.getTableListData()
    },
    //获取选中的区域最后一级id
    getAreaId() {
      var areaId = this.bizAreaId[this.bizAreaId.length - 1]
      this.filterField.bizAreaId = areaId
    },
    //获取选中的行业最后一级id
    getIndustryId() {
      var industryId = this.industryId[this.industryId.length - 1]
      this.filterField.industryId = industryId
    },
    //跳转审核页面
    skipCheckPage(id) {
      this.$router.push({
        name: 'checkPage',
        path: 'home/checkManage/checkPage',
        query: {
          id: id,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/enterpriseSet/employerAuditList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    //跳转详情页面
    toDetail(row) {
      this.$router.push({
        name: 'checkDetailPage',
        path: 'home/checkManage/checkDetailPage',
        query: {
          id: row.id,
          pageInfo: 'employerAuditList',
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/enterpriseSet/employerAuditList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    getApi() {
      if (localStorage.getItem('judgeRoleCode') === 'company') {
        this.api = 'api-s/report/export_JC_NC_COMPANY_AUDIT'
      } else {
        this.api = 'api-s/report/export_JC_CS_COMPANY_AUDIT'
      }
    },
  },
}
</script>

<style scoped lang="less">
.mainCon {
  top: 198px;
}
@media only screen and (max-width: 1366px) {
  /deep/.searchInputWidth .el-form--inline .el-form-item__label {
    width: 80px;
  }
}
@import '../../../static/css/filterArea.less';
</style>
